import { default as VueImport } from 'vue';
import { AppUILogicService } from './app-logic/appuilogic';
import { DesignModelEdit, DesignStylePreview, JsonSchemaFormEditor, ParameterDefinition, StylePickerItem, StylePreviewContent } from './ibz-studio-plugins';
import { Badge, NotificationSignal, IBzTooltip } from './directives';
import { AppComponentService } from './app-service';
import { IBzTooltipAsync } from './directives/ibz-tooltip/ibz-tooltip-async/ibz-tooltip-async';
import VueForm from '@lljj/vue-json-schema-form';

export const VueInstall = {
  install(vue: typeof VueImport, options: Record<string, any>): void {
    // 避免出现重复实例化
    if ((window as any).___ibz___uilogic_init === true) {
      return;
    }
    (window as any).___ibz___uilogic_init = true;
    (window as any).UILogicService = AppUILogicService.getInstance();
    (window as any).plugin.DeAcModeMap.set('StylePickerItem', new StylePickerItem());
    // 注册指令
    vue.directive('badge', Badge);
    vue.directive('nsc', NotificationSignal);
    vue.directive('ibz-tip', IBzTooltip);
    // 视图注册
    vue.component('VueForm', VueForm);
    vue.component('app-model-edit', DesignModelEdit);
    vue.component('app-style-preview', DesignStylePreview);
    vue.component('style-preview-content', StylePreviewContent);
    vue.component('parameter-definition', ParameterDefinition);
    vue.component('json-schema-form-editor', JsonSchemaFormEditor);
    vue.component('ibz-tooltip-async', IBzTooltipAsync);

    AppComponentService.hooks.editor_register.tap(map => {
      map.set('TEXTAREA_ParameterDefinition', 'parameter-definition');
      map.set('CODE_JsonSchemaFormEditor', 'json-schema-form-editor');
    });
  },
};
